package com.prs.crm.domain.stock;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.BaseEntity;

/**
 * 产品分类
 * @author prs.chenzhi
 *
 */
@Entity
@Table(name="stock_productclass")
public class ProductClass extends BaseEntity{
	
	private static final long serialVersionUID = 1L;

	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private String name;
	
	@ManyToOne
	private ProductClass parent;
	
	@OneToMany(mappedBy="parent",fetch=FetchType.LAZY)
	private Set<ProductClass> childClasses;
	
	@OneToMany(mappedBy="productClass",fetch=FetchType.LAZY)
	@OrderBy
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<ClassAttribute> attributes;
	
	private String remark;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRemark() {
		return remark;
	}

	public void setParent(ProductClass parent) {
		this.parent = parent;
	}

	public ProductClass getParent() {
		return parent;
	}

	public void setChildClasses(Set<ProductClass> childClasses) {
		this.childClasses = childClasses;
	}

	public Set<ProductClass> getChildClasses() {
		return childClasses;
	}

	public void setAttributes(Set<ClassAttribute> attributes) {
		this.attributes = attributes;
	}

	public Set<ClassAttribute> getAttributes() {
		return attributes;
	}
	
	public void addAttribute(ClassAttribute attribute)
	{
		if (attributes==null)
			attributes = new HashSet<ClassAttribute>();
		attributes.add(attribute);
	}
}
